<%@ page language="java" pageEncoding="UTF-8" %>
<% 
    String context = request.getContextPath();
    request.setAttribute("context",context);
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>用户</title>
    <link href="${context}/static/jquery-easyui-1.3.2/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="${context}/static/jquery-easyui-1.3.2/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="${context}/static/jquery-easyui-1.3.2/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="${context}/static/jquery-easyui-1.3.2/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="${context}/static/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="${context}/static/scripts/json2.js" type="text/javascript"></script>
    <script src="${context}/static/scripts/common.js" type="text/javascript"></script>
    <link href="${context}/static/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <script src="${context}/static/bootstrap/js/bootstrap.js" type="text/javascript"></script>    
    <style type="text/css">
        body {
            padding: 0px;
            margin: 0px;
        }
    </style>
    
    <script type="text/javascript">
   	    var _currentNode;
    	var _currentRow;
        $(document).ready(function () {
        	initRightGrid();
			initLeftTree();
			loadleftTree();
        });
        
		function initLeftTree() {
		    $("#catalogueTree").tree({
		        checkbox: false,
		        dnd: false,
		        onClick: function (node) {
		           	_currentNode=node;
		           	initRightGrid();
		           	loadRightGrid();   
		        }, 
		        onContextMenu: function (e, row) {
		        }, 
		        onLoadSuccess: function (note, data) {
		        	_currentNode=null;  
		            if (data.length > 0) {
		                var node =  $("#catalogueTree").tree("getRoot");
		                $("#catalogueTree").tree("select", node.target);
		                _currentNode=node;
			           	initRightGrid();
			           	loadRightGrid(); 
		            }else {
		            	linkButtonsDisable(["新增","修改","删除"], $("#TreeButtonsPanel"));
		            	linkButtonsDisable(["新增用户","修改用户","删除用户","密码重置"], $("#GridButtonsPanel"));
		            }            	
		        }, 
		        onDrop: function (e, source) {
		        }
		    });    
		} 
		
		function loadleftTree() {  
		    $("#catalogueTree").tree("loadData", ${treeNodes});
		}		
		
		function initRightGrid() {
		    $("#dataGrid").datagrid({
		        fit: true,
		        nowrap: true,
		        fitColumns: true,
		        rownumbers: true,
		        singleSelect: true,
		        striped: true,
		        pagination:true,
		        columns: [
			        [{"field":"id","title":"主键","width":80,"align":"left","hidden":true},
			        {"field":"title","title":"标题","width":160,"align":"left"},
			        {"field":"remark","title":"备注","width":80,"align":"left","hidden":true},
			        {"field":"author","title":"作者","width":50,"align":"left"},
			        {"field":"publicDate","title":"发布时间","width":80,"align":"left"},
			        {"field":"content","title":"内容","width":80,"align":"left","hidden":true},
			        {"field":"contentURL","title":"内容链接","width":80,"align":"left"},
			        {"field":"excerptsUrl","title":"摘录地址","width":80,"align":"left"},
			        {"field":"type","title":"类型","width":80,"align":"left","hidden":true},
			        {"field":"sourceType","title":"来源类型","width":80,"align":"left","hidden":true}]
		        ],
				onClickRow: function (row) {
					_currentRow=$("#dataGrid").datagrid("getRows")[row];
				}, 
				onDblClickRow: function (rowIndex, field, value) {	
					$("#divContent").html(_currentRow.content);
					$('#myModal').modal('show')					
				}, 
				onAfterEdit: function (rowIndex, rowData, changes) {
				}, 
				onLoadSuccess: function (data) {
					_currentRow=null;
					var node =  $("#catalogueTree").tree("getRoot");
					var treeButtonDisabled=[];
					if(node.id==_currentNode.id) {
						treeButtonDisabled.push("修改");
						treeButtonDisabled.push("删除");
					}
		        	linkButtonsDisable(treeButtonDisabled, $("#TreeButtonsPanel"));			
		        	linkButtonsDisable(["修改用户","删除用户","密码重置"], $("#GridButtonsPanel"));			
				}
		    });     
		    
		    //分页控件设置
		    var pager = $("#dataGrid").datagrid("getPager");
		    pager.pagination({
		        onSelectPage: function (pageNumber, pageSize) {
		        	var option = $("#dataGrid").datagrid("options");//确保第二页序号不从1开始
		            option.pageSize = pageSize;
		            option.pageNumber = pageNumber;
		        	var param={};
		            pageNumber = parseInt(pageNumber, 10);
		            pageSize = parseInt(pageSize, 10);
		            param.page=pageNumber;
		            param.size=pageSize;
		            param.sourceType=_currentNode.id;
		            loadRightGrid(param);
		        }
		    }); 
		}		
		
		function loadRightGrid(paramPager) {
			var pager=$("#dataGrid").datagrid("getPager");
			if(!paramPager) paramPager={"page":1,"size":parseInt(pager.pagination("options").pageSize, 10),"sourceType":_currentNode.id};
		    $.ajax({
		        url: "${context}/wslist/getPagerList.html",
		        data: paramPager,
		        dataType: "json",
		        type: "GET",
		        async: false,
		        success: function (result) {
		        	var rows=result.rows;
		            $("#dataGrid").datagrid("loadData", { total: result.total, rows: result.rows });
		            $("#dataGrid").datagrid("loaded");
		        }
		    });	
			
		}  		        
        
        
    </script>
</head>
<body>
    <div class="easyui-layout" style="width: 100%; height: 100%;">
        <div region="west" split="true" border="false" title="文章来源" style="width: 220px; overflow: auto; padding-top: 0px;">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%; font-size: 12px;">
                <tr>
                    <td style="vertical-align: top;">
                        <ul id="catalogueTree">
                        </ul>
                    </td>
                </tr>
            </table>
        </div>
        <div region="center" border="false" style="overflow: hidden;">
            <div class="easyui-layout" style="width: 100%; height: 100%;" fit="true">
                <div region="north" border="false" split="false" style="height: 32px; overflow: auto; padding-top: 0px; background-color: #e9f1fe;">
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%; font-size: 12px; border-bottom: 1px solid #99bbe8;">
                        <tr>
                            <td>
                                <div id="GridButtonsPanel" style="padding: 2px 5px 2px 5px;float:right">
                                    <a id="updateRight"  href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="tabUpdate('update');return false;" iconcls="icon-updatefile" style="float: left" disabled="true">修改</a>
                                    <a id="deleteRight"  href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="deleteRightRecord();return false;" iconcls="icon-deletefile" style="float: left" disabled="true">删除</a>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div region="center" border="false" style="overflow: hidden;">
                    <table id="dataGrid" border="false">
                    </table>
                </div>
            </div>
        </div>
    </div>  
    
    <div id="myModal" class="modal hide fade" style="width:50%;margin-right:auto;">
      <div class="modal-header">
        <a class="close" data-dismiss="modal" >&times;</a>
        <h3>文章内容</h3>
      </div>
      <div id="divContent" class="modal-body">
      	
      </div>
      <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal" >关闭</a>
      </div>
    </div>      
</body>
</html>
